home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
oop_tp55.zip
/
TRIANGLE.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1990-02-11
|
3KB
|
120 lines
program TPuzzle;
uses Trigl,ListObj,Crt,Dos;
const
BasicSetups : array[1..4] of String15 = ( 'XXXXXXXXXXXXXXO',
'XXXXOXXXXXXXXXX',
'XXXXXXXXXOXXXXX',
'XXXOXXXXXXXXXXX' );
type
Pair = array[1..2] of word;
BetterTrigl = object(Triangle)
procedure GenChild( NewPosition : String15 ); virtual;
function Heuristic : boolean; virtual;
end;
function BetterTrigl.Heuristic : boolean;
begin
if not ((Generation = 9) and (Position[5] = 'O') and
(Position[8] = 'O') and
(Position[9] = 'O')) then
Heuristic := true
else
Heuristic := false;
end;
procedure BetterTrigl.GenChild( NewPosition : String15 );
var
pNewTriangle : ^BetterTrigl;
begin
New( pNewTriangle, Init( NewPosition, Succ(Generation) ) );
{ comment out next line for speedup }
pNewTriangle^.ShowPosition;
Offspring.Prepend( pNewTriangle );
Offspring.Cursor := OffSpring.Head;
end;
procedure TimeDiff( H, M, S, HS : Pair);
var
MS, SS : string[2];
begin
if S[2] < S[1] then
begin
S[2] := S[2] + 60;
Dec(M[2]);
end;
if M[2] < M[1] then
begin
M[2] := M[2] + 60;
Dec(H[2]);
end;
if H[2] < H[1] then
H[2] := H[2] + 24;
gotoXY(1,1);
Str( M[2]-M[1], MS );
Str( S[2]-S[1], SS );
if Length(MS) = 1 then MS := Concat( '0', MS );
if Length(SS) = 1 then SS := Concat( '0', SS );
GoToXY( 1,3 );
writeln('Elapsed time = ', H[2]-H[1], ':', MS,
':', SS );
end;
var
T : Triangle;
B : BetterTrigl;
H,M,S,HS : Pair;
Choice : integer;
begin
ClrScr;
GoToXY(1,1);
write( '1:' );
DisplayPosition( BasicSetups[1], 3, 1 );
GoToXY(40,1);
write( '2:' );
DisplayPosition( BasicSetups[2], 42,1 );
GoToXY(1,12);
write( '3:' );
DisplayPosition( BasicSetups[3], 3, 12 );
GoToXY(40,12);
write( '4:' );
DisplayPosition( BasicSetups[4], 42, 12 );
repeat
GoToXY( 5, 23 );
write( 'Select a starting position (1-4): ');
GoToXY( 39,23);
readln( Choice );
until (Choice >0) and (Choice<5);
ClrScr;
writeln('STANDARD TRIANGLE:');
T.Init( BasicSetups[Choice],0);
GetTime( H[1], M[1], S[1], HS[1] );
if T.FindWin = true then
begin
GetTime( H[2], M[2], S[2], HS[2] );
TimeDiff( H,M,S,HS);
T.ShowWin;
T.ShowStats;
end;
ClrScr;
writeln( 'BETTER TRIANGLE:' );
InitStats; { must be done explicitly after the first time }
B.Init( BasicSetups[Choice],0 ); { Shortest solution time }
GetTime( H[1], M[1], S[1], HS[1] );
if B.FindWin = true then
begin
GetTime( H[2], M[2], S[2], HS[2] );
TimeDiff( H,M,S,HS);
B.ShowWin;
B.ShowStats;
end;
end.